package IO;

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

/**
 * @author wuhan
 * @date 2019/10/10 10:08
 */
public class RealizationReadline {
    public static void main(String[] args) throws IOException {
            FileReader fileReader=new FileReader("buf.txt");
            MyBufferedReader myBufferedReader=new MyBufferedReader(fileReader);
            String s=null;
            while ((s=myBufferedReader.myReadLine())!=null){
                System.out.println(s);
            }
    }
}

/**
 * 装饰设计模式
 */
class MyBufferedReader{
    private FileReader r;
    MyBufferedReader(FileReader r){
        this.r=r;
    }
    public String myReadLine() throws IOException {
        StringBuilder sb=new StringBuilder();
        int ch=0;
        while ((ch=r.read())!=-1){
            if (ch=='\r')
                continue;
            if (ch=='\n')
                return sb.toString();
            else
                sb.append((char) ch);
        }
        if (sb.length()!=0)
            return sb.toString();
        return null;
    }
    public void myCLose() throws IOException {
        r.close();
    }
}